package com.synway.scheduling;

import com.synway.handler.SpiderHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;



@Component
public class SpiderTaskScheduling {
    @Value("${python.rootPath}")
    private String rootPath;
    @Value("${python.env}")
    private String pythonEnv;

    @Autowired
    private AmqpTemplate rabbitTemplate;

    //每天5：00执行,只执行成都差不多半小时执行完
    @Scheduled(cron = "0 00 05 ? * *")
    private void taskForLoupan() {

        SpiderHandler.rabbitTemplate =rabbitTemplate;
        SpiderHandler.spiderHandler(rootPath,pythonEnv,"loupan.py");

    }

    //每天6：00执行,只执行成都差不多一小时执行完
    @Scheduled(cron = "0 00 06 ? * *")
    private void taskForErshou() {
        SpiderHandler.rabbitTemplate =rabbitTemplate;
        SpiderHandler.spiderHandler(rootPath,pythonEnv,"ershou.py");
    }

    //每天7：00执行
    @Scheduled(cron = "0 00 07 ? * *")
    private void taskForXiaoqu() {
        SpiderHandler.rabbitTemplate =rabbitTemplate;
        SpiderHandler.spiderHandler(rootPath,pythonEnv,"xiaoqu.py");
    }

    //每天8：00执行
    @Scheduled(cron = "0 00 08 ? * *")
    private void taskForZufang() {
        SpiderHandler.rabbitTemplate =rabbitTemplate;
        SpiderHandler.spiderHandler(rootPath,pythonEnv,"zufang.py");
    }


}
